#pragma once
#include "Singleton.h"
#include <list>
struct IDirectInput8A;
struct IDirectInputDevice8A;

class InputManager : public Singleton<InputManager>
{
	friend class WindowsMessage;
public:
	class Listener
	{
	public:
		virtual ~Listener() {}

		virtual bool OnMouseMove(long deltaX, long deltaY) { return false; }
		virtual bool MsgProc(void* hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { return false; }
	};
	typedef std::list<Listener*> ListenerList;

public:
	InputManager(void);
	~InputManager(void);

	bool Init(void* hWnd);
	void Update(float elapsedTime);

	void AddListener(Listener* listener);
	void RemoveListener(Listener* listener);

	bool getImmediateMode() const { return mImmediateMode; }
	void setImmediateMode(bool v);
	void switchImmediateMode() { setImmediateMode(!getImmediateMode()); }

private:
	bool MsgProc(void* hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

	// dinput method.
	void OnMouseMove(long deltaX, long deltaY);

	void CheckMouseInput();

	ListenerList mListeners;
	IDirectInput8A* mDirectInput;
	IDirectInputDevice8A* mMouseDevice;
	void* mWnd;
	bool mActive;
	bool mImmediateMode;
};
